package cate.game.play.skill.passive.talent;

import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.Comparator;

/**
 * 使用治疗技能时，有45%概率净化优先处于控制状态的2名队友
 */
public class 净化PH extends PassiveHandler {


	private int 概率;

	private int 人数;

	//概率=4500&人数=2
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
		人数 = args.getInt("人数", 0);
	}

	@Override
	public void onSkillDone(SkillActionCtx action) {
		if (!XT.chance(概率)) {
			return;
		}
		if (!action.getSkill().cfg.isEffectType(GDSkill.EffectType.治疗)) {
			return;
		}
		skill.owner.getFightTeam().getFriendsAlive(skill.owner).stream().
				sorted(Comparator.comparing(f -> !f.buff.underCtrl())).
				limit(人数).forEach(f -> f.buff.tryDispelBad(action));
	}
}
